package fr.afcepf.ai89.esharing.managedbean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import fr.afcepf.ai89.esharing.entity.Aem;
import fr.afcepf.ai89.esharing.entity.Avis;
import fr.afcepf.ai89.esharing.entity.Proprietaire;
import fr.afcepf.ai89.esharing.metier.BusinessRechercheAem;
import fr.afcepf.ai89.esharing.metier.IBusinessRechercheAem;

public class FicheAemManagedBean {
	
	private String codePostal = "";
	private String descriptif = "";
	private String noteMoyenne = "";
	private String valeurJournalière = "";
	private String dateDebut;
	private String dateFin;
	private AEMView monAem;
	private List<AvisSurPreteurView> avisSurCeci;
	private List<AEMView> aemsProp;
	private ResultatRechercheManagedBean mbRecherche;
	private IBusinessRechercheAem busRech = new BusinessRechercheAem();
	
	public void demanderEmprunt() {
		//System.out.println("demande d'emprunt envoyé !");
	}
	

	public String getDateDebut() {
		return dateDebut;
	}

	public void setDateDebut(String dateDebut) {
		this.dateDebut = dateDebut;
	}

	public String getDateFin() {
		return dateFin;
	}

	public void setDateFin(String dateFin) {
		this.dateFin = dateFin;
	}

	public String getCodePostal() {
		return codePostal;
	}
	public void setCodePostal(String codePostal) {
		this.codePostal = codePostal;
	}
	public String getDescriptif() {
		return descriptif;
	}
	public void setDescriptif(String descriptif) {
		this.descriptif = descriptif;
	}
	public String getNoteMoyenne() {
		return noteMoyenne;
	}
	public void setNoteMoyenne(String noteMoyenne) {
		this.noteMoyenne = noteMoyenne;
	}
	
	public String getValeurJournalière() {
		return valeurJournalière;
	}
	public void setValeurJournalière(String valeurJournalière) {
		this.valeurJournalière = valeurJournalière;
	}


	public ResultatRechercheManagedBean getMbRecherche() {
		return mbRecherche;
	}


	public void setMbRecherche(ResultatRechercheManagedBean mbRecherche) {
		this.mbRecherche = mbRecherche;
	}


	public AEMView getMonAem() {
		
		int idA = mbRecherche.getAemAficher();
		Aem a = busRech.getFicheAem(idA);
		
		AEMView unAemVoir = new AEMView();
		unAemVoir.setAem(a);
		monAem = unAemVoir;
		
		System.out.println("The link to the picture is : " + monAem.getImg());
		
		return monAem;
		
	}


	public void setMonAem(AEMView monAem) {
		this.monAem = monAem;
	}
	
	public FicheAemManagedBean() {
				
	}


	public List<AEMView> getAemsProp() {
		
		Proprietaire p = new Proprietaire();
		p = busRech.getFicheAem(mbRecherche.getAemAficher()).getProprietaire();

		List<Aem> aemsToAdd = busRech.getAems(p);
		List<AEMView> maListe = new ArrayList<AEMView>();
		
		for (Aem a : aemsToAdd) {
			
			AEMView av = new AEMView();
			av.setAem(a);
			
			System.out.println("*******THIS IS MY AEM : " + a.getMarque().getIdMarque() + "********");
			System.out.println("*******THIS IS MY AEMVIEW : " + av.getAem().getMarque().getIdMarque() + "********");
			
			maListe.add(av);
			
		}
		
		aemsProp = maListe;
		return aemsProp;
		
	}


	public void setAemsProp(List<AEMView> aemsProp) {
		this.aemsProp = aemsProp;
	}


	public List<AvisSurPreteurView> getAvisSurCeci() {
		
		Aem aAviser = monAem.getAem();
		
		List<Avis> cesAvis = busRech.getAvisEmprunteur(aAviser);
		List<AvisSurPreteurView> listAvis = new ArrayList<AvisSurPreteurView>();
		
		for (Avis av : cesAvis) {
			
			AvisSurPreteurView asp = new AvisSurPreteurView();
			
			System.out.println("**********" + av.getNoteAvis() + "/ 5 **********");
			asp.setAvis(av);
			
			listAvis.add(asp);
			
		}
		
		avisSurCeci = listAvis;
		return avisSurCeci;
		
	}


	public void setAvisSurCeci(List<AvisSurPreteurView> avisSurCeci) {
		this.avisSurCeci = avisSurCeci;
	}
	
	
}
